class Main extends egret.DisplayObjectContainer {
    private hajime: Hajime;
    private bg: egret.Bitmap;
    private BGUp: egret.Bitmap;

    private page1: Page1;
    private page2: Page2;
    private page3: Page3;
    private page4: Page4;
    private page5: Page5;
    private page6: Page6;
    private page7: Page7;
    private page8: Page8;
    private BP: BlinkPoint;
    public constructor() {
        super();
        this.hajime = new Hajime();
        this.hajime.addEventListener(GoEvent.ResourceLoaded, this.ResourceLoaded, this);
        this.addChild(this.hajime);

        var keyboard = new KeyBoard();
        keyboard.addEventListener(KeyBoard.onkeydown, this.PressKey, this);

        GoEvent.initial();
        GoEvent.msg.addEventListener("ChangePage", this.ChangePage, this)

    }
    private ResourceLoaded(e: GoEvent) {
        this.removeChild(this.hajime);

        this.BGUp = new egret.Bitmap(RES.getRes("BGUp_png"));
        this.BGUp.x = 60; this.BGUp.y = 24;



        this.page1 = new Page1();
        this.page2 = new Page2();
        this.page3 = new Page3();
        this.page4 = new Page4();
        this.page5 = new Page5();
        this.page6 = new Page6();
        this.page7 = new Page7();
        this.page8 = new Page8();
        this.addChild(this.page1);

        // this.addChild(this.page4);
        // this.page4.Show();


        this.BP = new BlinkPoint();
        // this.addChild(this.BP);
        this.BP.Show();

        this.addChild(this.BGUp);

        // this.addEventListener(egret.Event.ENTER_FRAME, this.EF, this);
    }
    // private EF(e: egret.Event) {
    //     if (this.page2.parent && this.page2.alpha == 0) {
    //         this.removeChild(this.page2);
    //     }
    // }
    private ChangePage(e: GoEvent) {
        switch (e.data) {
            case "2": console.log("Page2");
                this.page1.End();
                this.addChild(this.page2);
                this.page2.Show();
                break;
            case "3": console.log("Page3");
                this.page2.End();
                this.addChild(this.page3);
                this.page3.Show();
                break;
            case "4": console.log("Page4");
                this.page3.End();
                this.addChild(this.page4);
                this.page4.Show();
                break;
            case "5": console.log("Page5");
                this.page4.End();
                this.addChild(this.page5);
                this.page5.Show();
                break;
            case "6": console.log("Page6");
                this.page5.End();
                this.addChild(this.page6);
                this.page6.Show();
                break;
            case "7": console.log("Page7");
                this.page6.End();
                this.addChild(this.page7);
                this.page7.Show();
                break;
            case "8": console.log("Page8");
                this.page7.End();
                this.addChild(this.page8);
                this.page8.Show();
                break;
        }
        if (e.data != "4") {
            this.addChild(this.BP);
            this.BP.Show();
        }
        this.addChild(this.BGUp);
    }

    private PressKey(e) {
        if (e.data == "A") {
            console.log("A");
        }
        if (e.data == "D") {
            console.log("D");
        }
    }
}